<include file=".:Common:header" />
<script language="javascript">
$(function(){
	$('form').form({ 
		success:function(data){
			var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				alertText(data.info, 'success', '{:U('Role/index')}');
			}
		}   
	}); 
}); 
</script>
<div class="wrapper clear">
	<div class="main">
	<if condition="!empty($button)">
            <div class="toolbar">
                <volist name="button" id="btn">
                <a href="{$btn.href}" id="add1" title="{$btn.text}">{$btn.text}</a>
                </volist>
            </div>
            </if>
		<div class="search">
            <div class="searchbox">
            
<link href="/public/css/table.css" rel="stylesheet" type="text/css">
<style type="text/css">
#LD a, #LD a:visited { color:#003264}
.list-div table th span { height:30px; line-height:30px; border-right:1px solid #BBDDE5; display:block; background:none; float:left; padding:0px 10px; overflow:hidden; cursor:pointer}
.list-div table tr { background:#FFFFFF;}
.list-div table th .cur { background:#F4FAFF; }
.ur_heres { height:35px; padding-left:20px; line-height:35px; overflow:hidden; font-size:14px; font-weight:bold; background:#F4FAFF}
.p { width:170px; height:25px; line-height:25px; text-align:left; float:left; overflow:hidden; display:block;}
</style>
<form action="{:U('Role/topurview')}&ajax=true" method="post">
  <div class="form-div" style="width:100%">
   <span style="float:right;">
    <label for="all">
    <input type="checkbox" name="all" id="all" value="all" <php> if($pur[0]=='all'){ echo 'checked'; }</php>/>
    系统内部所有模块权限</label>
    </span>当前岗位：<b><php> echo $thisgw; </php></b>
    <input style="margin-left:25px; height:30px" type="button" id="clearAll" value="清除所有权限" class="button"/>
    <input style="height:30px" type="reset" value="重新设置" class="button" />
  </div>
 
  <div class="easyui-tabs">
  <php>$i=0; $thisid=0;</php>
  <foreach name="treeall" item="tree">
		<div title="{$tree.name}" style="padding:10px;">
			  <div class="list-div" id="moduleDIV" <php> if($pur[0]=='all'){ echo 'style="display:none;"'; }</php>>
    <table>
      <tbody>
        <tr>
          <th scope="col" style="padding-left:10px; border-bottom:none;"> <php>foreach($tree['child'] AS $key=>$main){</php>
            <span <php> if($i == 0): $thisid=$tree['id'].$main['id'];</php> class="cur"<php> ;endif;</php> id="span_<php> echo $tree['id'].$main['id']; </php>" onClick="showMD('<php> echo $tree['id'].$main['id']; </php>')"><php> echo $main['name'];</php></span>
            <php> $i++; } </php>
          </th>
        </tr>
        <tr>
          <td style=" border-bottom:2px solid #EEF8F9; padding-left:0px;"><php> if (isset($tree['child'] )){</php>
            <php> $j=0; foreach($tree['child'] AS $key=>$main){</php>
            <div id="table_<php> echo $tree['id'].$main['id']; </php>" <php> if($j!=0){</php> style="display:none; margin-top:0px;"<php> }</php>>
              <table width="100%" class="listdiv" id="LDTOP" style=" border:none; ">
                <tr>
                  <td style="padding-left:20px; padding-top:10px; padding-bottom:10px;background:#F4FAFF;" width="15%"><b style="font-size:14px;"><php> echo $main['name'];</php></b></td>
                  <td width="85%" style="padding-left:20px; padding-top:10px; padding-bottom:10px;background:#F4FAFF;"><p class="p">
                      <label for="<php> echo "main_".$main['id']; </php>">
                      <input type="checkbox" id="<php> echo "main_".$main['id']; </php>" name="purview[]" value="<php> echo $main['tag']; </php>" <php> if(in_array($main['tag'], $pur)){ echo 'checked'; }</php>/>
                      显示主模块菜单</label>
                    </p></td>
                </tr>
              </table>
              <php> if(isset($main['child'])){</php>
              <php> foreach ($main['child'] AS $ck=>$ch){</php>
              <table width="100%" class="listdiv" id="LD" style=" border:none">
                <tr>
                  <td style="padding-left:20px; padding-top:5px; padding-bottom:5px;" width="15%"><b style="font-size:13px;<php> if(1 == $ch['type']){</php>color:#005EBB<php> }</php>"><php> echo $ch['name']</php></b></td>
                  <td width="85%" style="padding-left:20px; padding-top:5px; padding-bottom:5px;"><php> if(isset($ch['child'])){</php>
                    <div style="display:block; overflow:hidden; height:35px;">
                      <p class="p">
                        <label for="<php> echo "id".$ch['id']."_all"; </php>">
                        <input type="checkbox" id="<php> echo "id".$ch['id']."_all"; </php>" name="purview[]" value="<php> echo $ch['tag']."_all"; </php>" <php> if(in_array($ch['tag']."_all", $pur)){ echo 'checked'; }</php> onClick="selectPur('<php> echo "id".$ch['id']."_"; </php>')"/>
                        选择下级所有模块权限</label>
                      </p>
                      <php> if(!$ch['type']){</php>
                      <p class="p">
                        <label for="<php> echo "id".$ch['id']."_showmenu"; </php>">
                        <input type="checkbox" id="<php> echo "id".$ch['id']."_showmenu"; </php>" name="purview[]" onClick="checkMainPur()" value="<php> echo $ch['tag']; </php>" <php> if(in_array($ch['tag'], $pur)){ echo 'checked'; }</php>/>
                        显示菜单</label>
                      </p>
                      <php> }</php>
                    </div>
                    <php> foreach ($ch['child'] AS $k=>$c){</php>
                    <p class="p">
                      <label for="<php> echo "id".$ch['id']."_".$c['id'];</php>">
                      <input type="checkbox" name="purview[]" onClick="checkPur('<php> echo "id".$ch['id']."_"; </php>')" align="texttop" id="<php> echo "id".$ch['id']."_".$c['id'];</php>" value="<php> echo $c['tag']</php>" <php> if(in_array($c['tag'], $pur)){ echo 'checked'; }</php>/>
                      <b style="color:#005EBB"><php> echo $c['name']</php></b> </label>
                    </p>
                    <php> }</php>
                    <php> }</php></td>
                </tr>
              </table>
              <php> }</php>
              <php> }</php>
            </div>
            <php> 	$j++; } //end foreach</php>
            <php> } //end if</php></td>
         <input name="id" type="hidden"  value="{$id}"
        </tr>
      </tbody>
    </table>
  </div>
    <div class="form-div" style="text-align:center; margin-top:3px;">
    <input style="height:30px" type="submit" value="保存" class="button" onclick="return $('form').form('validate')"/>
    <input style="height:30px" type="reset" value="重置" class="button"/>
  </div>
		</div>
   </foreach>
		<!--<div title="网络测试" closable="true" style="padding:10px;">
			Second Tab
		</div>
		<div title="性能测试" iconCls="icon-reload" closable="true" style="padding:10px;">
			Third Tab
		</div>-->
	</div>
    
</form>          
            
            
            </div>
		</div>
	</div>
</div>	            
<script language="javascript">
var span = <php> echo $thisid;</php>;
function showMD(id){
	if(id == span){
		return false;
	}
	$("#span_"+id).css({background:"#F4FAFF"});
	$("#span_"+span).css({background:"none"});
	$("#table_"+id).show();
	$("#table_"+span).hide();
	span = id;
}
$(function(){
	$("#LD tr").hover(
		function(){
		$(this).css({background:"#E6F2F7"});
		},
		function(){
		$(this).css({background:"#ffffff"});
		}
	);
	$("#all").click(function(){
		if($("#all").attr("checked")){
			$("#moduleDIV").hide();
		}else{
			$("#moduleDIV").show();
		}
	});
	$("#clearAll").click(function(){
		$("input[name^='purview']").each(function(){
			$(this).attr("checked", false);
		});
	});
});
//选择下级所有模块
function selectPur(idp){
	if($("#"+idp+"all").attr("checked")){
		$("input[id^='"+idp+"'][name^='purview']").each(function(){
			$(this).attr("checked", true);
		});
	}else{
		$("input[id^='"+idp+"'][name^='purview']").each(function(){
			$(this).attr("checked", false);
		});
	}
	checkMainPur();
}
function checkPur(idp){
	var is_checked = $("#"+idp+"all");
	var is_checked_show = $("#"+idp+"showmenu");
	var to_checked = true;
	var to_checked_show = false;
	$("input[id^='"+idp+"'][name^='purview']").each(function(){
		if(!$(this).attr("checked") && $(this).attr("id") != is_checked.attr("id")){
			to_checked = false;
		}
		if($(this).attr("checked") && $(this).attr("id") != is_checked_show.attr("id")){
			to_checked_show = true;
		}
	});
	if(is_checked){
		if(to_checked){
			$("#"+idp+"all").attr("checked", true);
		}else $("#"+idp+"all").attr("checked", false);
	}else{
		if(!to_checked){
			$("#"+idp+"all").attr("checked", true);
		}else $("#"+idp+"all").attr("checked", false);
	}
	if(to_checked_show){
		$("#"+idp+"showmenu").attr("checked", true);
	}else $("#"+idp+"showmenu").attr("checked", false);
	//选择主菜单项
	checkMainPur();
}

function checkMainPur(){
	var to_check_main = false;
	$("#table_"+span+" input").each(function(){
		if($(this).attr("checked") && $(this).attr("id") != $("#main_"+span).attr("id")){
			to_check_main = true;
		}
	});
	if(to_check_main){
		$("#main_"+span).attr("checked", true);
	}else{
		$("#main_"+span).attr("checked", false);
	}
}
</script>
<include file=".:Common:footer" />